package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.CwProductCategory;
import com.ruoyi.system.service.ICwProductCategoryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 盲盒分类Controller
 * 
 * @author hyx
 * @date 2024-11-21
 */
@RestController
@RequestMapping("/cwcategory")
public class CwProductCategoryController extends BaseController
{
    @Autowired
    private ICwProductCategoryService cwProductCategoryService;

    /**
     * 查询盲盒分类列表
     */
    @RequiresPermissions("system:cwcategory:list")
    @GetMapping("/list")
    public TableDataInfo list(CwProductCategory cwProductCategory)
    {
        startPage();
        List<CwProductCategory> list = cwProductCategoryService.selectCwProductCategoryList(cwProductCategory);
        return getDataTable(list);
    }

    /**
     * 导出盲盒分类列表
     */
    @RequiresPermissions("system:cwcategory:export")
    @Log(title = "盲盒分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CwProductCategory cwProductCategory)
    {
        List<CwProductCategory> list = cwProductCategoryService.selectCwProductCategoryList(cwProductCategory);
        ExcelUtil<CwProductCategory> util = new ExcelUtil<CwProductCategory>(CwProductCategory.class);
        util.exportExcel(response, list, "盲盒分类数据");
    }

    /**
     * 获取盲盒分类详细信息
     */
    @RequiresPermissions("system:cwcategory:query")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(cwProductCategoryService.selectCwProductCategoryByCategoryId(categoryId));
    }

    /**
     * 新增盲盒分类
     */
    @RequiresPermissions("system:cwcategory:add")
    @Log(title = "盲盒分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CwProductCategory cwProductCategory)
    {
        return toAjax(cwProductCategoryService.insertCwProductCategory(cwProductCategory));
    }

    /**
     * 修改盲盒分类
     */
    @RequiresPermissions("system:cwcategory:edit")
    @Log(title = "盲盒分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CwProductCategory cwProductCategory)
    {
        return toAjax(cwProductCategoryService.updateCwProductCategory(cwProductCategory));
    }

    /**
     * 删除盲盒分类
     */
    @RequiresPermissions("system:cwcategory:remove")
    @Log(title = "盲盒分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(cwProductCategoryService.deleteCwProductCategoryByCategoryIds(categoryIds));
    }
}
